﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using SMS.Entities;
using System.Collections.Generic;
using SMS.DAL;

namespace SMS.Web.Service
{
    public class ProductService : IProductService
    {

        // Add more operations here and mark them with [OperationContract]

        //public System.Collections.Generic.List<Entities.Product> SearchProduct(string userName, string searchText, out SMSException serviceError)
        //{
        //    try
        //    {
        //        serviceError = null;
        //        return new SMS.DAL.ProductDA().SearchObject(userName, searchText);

        //    }
        //    catch (Exception ex)
        //    {
        //        serviceError = new SMSException(ex);
        //        return null;
        //    }
        //}
         public int SaveProduct(string userName, Entities.Product customer, out Entities.SMSException serviceError)
        {
            try
            {
                var retObj = new ProductDA().SaveObject(userName, customer);
                serviceError = null;
                return retObj.Product_ID;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return -1;
            }
        }

        public List<Entities.Product> SearchProduct(string userName, string searchText, out Entities.SMSException serviceError)
        {
            try
            {
                var retObj = new ProductDA().SearchObject(userName, searchText);
                serviceError = null;
                return retObj;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return null;
            }
        }
    }
}
